package avicit.bdp.dgs.qa.service.algo.raw.data.pcm;

import avicit.bdp.dgs.qa.dto.FtdpFileDTO;
import avicit.bdp.dgs.qa.dto.JobDTO;
import avicit.bdp.dgs.qa.dto.RuleDTO;
import avicit.platform6.core.rest.msg.ResponseMsg;
import com.alibaba.fastjson2.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;


/**
 * UT测试
 */
class PcmFileAlogTest {
    /**
     * 测试前，初始化数据
     */
    @Before
    public void beforTest() {

    }

    /**
     * 测试后，清理数据
     */
    @After
    public void afterTest() {

    }

    /**
     * 测试试飞原始文件校验算法（正常用例,PCM算法）
     */
    @Test
    public void testCase1() {
        // 构造模拟数据
        JobDTO jobDTO = mockJob();
        List<RuleDTO> ruleList = mockRuleList();
        List<FtdpFileDTO> fileList = mockFileList();

        // 方法调用
        ResponseMsg<List<FtdpFileDTO>> result = new PcmFileAlog().execute(jobDTO, ruleList);

        // 执行试飞工程值数据校验算法
        System.out.println(JSONObject.toJSONString(result));
    }

    /**
     * 测试试飞工程值数据算法（异常用例）
     */
    @Test
    public void testCase2() {

    }

    /**
     * 模拟文件校验任务
     *
     * @return
     */
    private JobDTO mockJob() {
        String jobJsonString = "{\n" +
                "\t\"id\": \"8a58bcf68b41dbb2018b6b29365624f4\",\n" +
                "\t\"name\": \"原始文件校验-自动创建-001\",\n" +
                "\t\"fileType\": 0,\n" +
                "\t\"fileTypeName\": \"原始数据\",\n" +
                "\t\"dataProp\": \"PCM\",\n" +
                "\t\"offsiteDataId\": \"8a58dab28ac9f9e4018ac9fb459700e8\",\n" +
                "\t\"typeName\": \"机载测试\",\n" +
                "\t\"aircraftName\": \"B-5008\",\n" +
                "\t\"flightDate\": \"2023-10-10\",\n" +
                "\t\"modelCode\": \"XH001\",\n" +
                "\t\"sortie\": \"1\",\n" +
                "\t\"testSystemName\": \"1号测试系统\",\n" +
                "\t\"resourceIds\": \"8a58dab28ac9f9e4018aca0470c50108,8a58dfc28adaa9a5018adae8599d013b\"\n" +
                "}";

        System.out.println(jobJsonString);
        return JSONObject.parseObject(jobJsonString, JobDTO.class);
    }

    /**
     * 模拟规则列表
     *
     * @return
     */
    private List<RuleDTO> mockRuleList() {
        String ruleJsonString = "{\n" +
                "\t\"createdBy\": \"平台管理员\",\n" +
                "\t\"creationDate\": \"2023-10-26 16:46:00\",\n" +
                "\t\"id\": \"8a58bcf68b6b1f40018b6b29719c01d8\",\n" +
                "\t\"jobId\": \"8a58bcf68b41dbb2018b6b29365624f4\",\n" +
                "\t\"lastUpdateDate\": \"2023-10-26 16:46:00\",\n" +
                "\t\"lastUpdatedBy\": \"1\",\n" +
                "\t\"measureType\": 3,\n" +
                "\t\"measureTypeName\": \"文件校验\",\n" +
                "\t\"name\": \"试飞原始文件校验\",\n" +
                "\t\"orgIdentity\": \"ORG_ROOT\",\n" +
                "\t\"templateId\": \"8a58a6c788ae86d20188aee282df0016\",\n" +
                "\t\"templateName\": \"试飞原始文件校验\",\n" +
                "\t\"templateType\": 0,\n" +
                "\t\"templateTypeName\": \"内置模板\",\n" +
                "\t\"version\": 0,\n" +
                "\t\"weight\": 10,\n" +
                "\t\"weightRatio\": 1.0\n" +
                "}";
        List<RuleDTO> ruleList = new ArrayList<>();
        ruleList.add(JSONObject.parseObject(ruleJsonString, RuleDTO.class));

        return ruleList;
    }

    /**
     * 模拟文件列表
     *
     * @return
     */
    private List<FtdpFileDTO> mockFileList() {
        String fileJsonString1 = "{\n" +
                "\t\"directory\": 5282794,\n" +
                "\t\"fullName\": \"991.inf\",\n" +
                "\t\"name\": \"991.inf\",\n" +
                "\t\"pid\": \"8a58bcf68b45edaa018b6b2693141df1\",\n" +
                "\t\"size\": 36,\n" +
                "\t\"type\": 0\n" +
                "}";
        String fileJsonString2 = "{\n" +
                "\t\"directory\": 0,\n" +
                "\t\"fullName\": \"991.PCM\",\n" +
                "\t\"name\": \"991.DCM\",\n" +
                "\t\"pid\": \"8a58bcf68b45edaa018b6b2693141df2\",\n" +
                "\t\"size\": 356622152,\n" +
                "\t\"type\": 0\n" +
                "}";

        List<FtdpFileDTO> fileList = new ArrayList<>();
        fileList.add(JSONObject.parseObject(fileJsonString1, FtdpFileDTO.class));
        fileList.add(JSONObject.parseObject(fileJsonString2, FtdpFileDTO.class));

        return fileList;
    }
}